package entity;

import java.io.Serializable;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

@XmlRootElement(name = "Project")
public class Project implements Serializable{

	private int id;
	private JSONArray guiDescriptor;
	private JSONArray dataProvider;
	private String projectName;

	public Project(JSONArray guiDescriptor, JSONArray dataProvider,	String projectName) {
		this.guiDescriptor = guiDescriptor;
		this.dataProvider = dataProvider;
		this.projectName = projectName;
	}
	
	public Project(int id, JSONArray guiDescriptor, JSONArray dataProvider,	String projectName) {
		this.id = id;
		this.guiDescriptor = guiDescriptor;
		this.dataProvider = dataProvider;
		this.projectName = projectName;
	}
	
	public Project(JSONObject jsonProject){
		
		try{
			this.id = jsonProject.getInt("id");
			this.guiDescriptor = jsonProject.getJSONArray("guiDescriptor");
			this.dataProvider = jsonProject.getJSONArray("dataProvider");
			this.projectName = jsonProject.getString("projectName");
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	
	public Project(){}
	
	public JSONObject getProjectToJSONObject(){
		
		JSONObject json = new JSONObject();
		
		try{
			json.put("id", id);
			json.put("guiDescriptor", guiDescriptor);
			json.put("dataProvider", dataProvider);
			json.put("projectName", projectName);
		}catch(JSONException e){
			e.printStackTrace();
		}
		
		return json;
	}

	@XmlElement
	public int getId(){ return id; }
	public void setId(int id){ this.id = id; }
	
	@XmlElement
	public JSONArray getGuiDescriptor() { return guiDescriptor; }
	public void setGuiDescriptor(JSONArray guiDescriptor) { this.guiDescriptor = guiDescriptor;}
	
	@XmlElement
	public JSONArray getDataProvider() { return dataProvider; }
	public void setDataProvider(JSONArray dataProvider) { this.dataProvider = dataProvider; }

	@XmlElement
	public String getProjectName() { return projectName; }
	public void setProjectName(String projectName) { this.projectName = projectName; }

	@Override
	public String toString() {
		return "Project [id=" + id + ", guiDescriptor=" + guiDescriptor
				+ ", dataProvider=" + dataProvider + ", projectName="
				+ projectName + "]";
	}

	

	}
